Support sorted series column for DF metrics#6347
Merged
alexanderbianchi merged 2 commits intoquickwit-oss:mainfrom Apr 29, 2026
Merged
Support sorted series column for DF metrics#6347alexanderbianchi merged 2 commits intoquickwit-oss:mainfrom
alexanderbianchi merged 2 commits intoquickwit-oss:mainfrom
Conversation
g-talbot
approved these changes
Apr 27, 2026
Contributor
g-talbot
left a comment
There was a problem hiding this comment.
LGTM, but maybe have Nga look at it too, as she was concerned about this.
4a1dc31 to
1b2efc2
Compare
1b2efc2 to
2274f5e
Compare
2274f5e to
4662634
Compare
4662634 to
26f903d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR wires the metrics DataFusion path to use the materialized
sorted_seriescolumn as the per-series grouping key for rollup-style queries. The metrics table provider now advertises split-local ordering bysorted_serieswhen the selected split metadata proves the default metrics sort schema, and the metrics runtime registers a physical optimizer rule that replaces the sorted-series hash repartition with a sort-preserving merge into a single final aggregate.It also keeps scan parallelism bounded to split/file partitions for metrics by disabling round-robin repartition injection and file-scan repartitioning in the metrics runtime registration.
Target Query Pattern
This targets the pre-series aggregation shape used by metrics rollups, where
sorted_seriesis the series handle and replaces the old context/points join onbhandle:Final Plan Shape
The important final physical shape is:
The core change is that the inner per-series finalization no longer requires:
Instead, workers emit split-local partial aggregates, the coordinator coalesces the ordered worker streams, and
SortPreservingMergeExecstitches them before a single final aggregate oversorted_series.The later repartition by
(service, time_bin)remains becausesorted_seriesordering does not imply partitioning by the outer aggregate key.Intake / Storage Assumptions
This optimization assumes intake and split metadata agree on the physical sort contract:
sort_fields == ProductType::Metrics.default_sort_fields()were written using that sort schemasorted_seriesfrom the same sort schema before sorting/reordering the batchsorted_seriesis monotonically non-decreasing in the physical Parquet row ordertimestamp_secsremains descending within a series under the default metrics sort schemaThe table provider only advertises the sorted-series ordering when all selected splits have the default metrics
sort_fields. Old splits with empty sort metadata or splits using custom sort fields do not get this advertised ordering, so the optimizer will not rely on a false ordering guarantee.Why Update Planning Rules
DataFusion can execute grouped aggregation in a streaming-friendly way when input is ordered by the group key. The default physical plan still inserted a hash repartition for the final aggregate over
sorted_series, which turns the distributed plan into a shuffle even though the split output can be sorted and merge-stitched.The metrics-specific physical rule rewrites only the sorted-series finalization pattern:
into:
That preserves correctness while avoiding the network/hash shuffle for the high-cardinality series key.
Future Considerations
Follow-up optimizations that are intentionally left out of this PR:
SortExecif the partial aggregate can prove it preserves sufficient sorted-series ordering.sorted_series -> tag columnsto avoid redundant grouping/sorting work on tag columns when safe.(service, time_bin)aggregate should hash repartition versus coalesce to a final reducer, based on the reduced inner-output cardinality.sorted_seriesfor parallel finalization without destroying sorted order.(sorted_series, time_bin).